﻿using DotNetCore.CAP;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace GeekTime.API.Application.IntegrationEvents
{
    /// <summary>
    /// 订阅服务 借助了ICapSubscribe  将服务标记为订阅服务
    /// </summary>
    public class SubscriberService : ISubscriberService, ICapSubscribe
    {

        IMediator _mediator;
        public SubscriberService(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary> 
        /// 订阅方法，订阅的处理函数上边标记CapSubscribe 将要订阅的事件名放在括号里，就可以订阅到这个事件了
        /// </summary>
        /// <param name="event"></param>
        [CapSubscribe("OrderPaymentSucceeded")]
        public void OrderPaymentSucceeded(OrderPaymentSucceededIntegrationEvent @event)
        {
            //Do SomeThing
        }
        [CapSubscribe("OrderCreated")]
        public void OrderCreated(OrderCreatedIntegrationEvent @event)
        {
            //Do SomeThing
            Console.WriteLine($"接受到的orderId：{@event.OrderId}");
        }
    }
}
